//package com.czf.testmodule.time.xxl_job;
//
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.http.HttpRequest;
//import cn.hutool.http.HttpResponse;
//import com.alibaba.fastjson.JSON;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.ResponseEntity;
//
//import org.springframework.util.MultiValueMap;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//import org.springframework.web.client.RestTemplate;
//
//import java.net.HttpCookie;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * @author zfChen
// * @create 2022/6/9 16:10
// */
//@RestController
//@Slf4j
//public class JobAddController {
//
//    @Autowired
//    private RestTemplate restTemplate;
//
//    @RequestMapping("/getCookie")
//    public String getCookie() {
//        String url = "http://127.0.0.1:8181/xxl-job-admin" + "/login";
////        ?userName={userName}&password={password}
//        HashMap<String, String> map = new HashMap<>();
//        map.put("userName", "admin");
//        map.put("password", "123456");
//        ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, map, String.class);
////        ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class, map);
//        log.info("response:{}", JSON.toJSONString(responseEntity));
//        List<String> cookies = responseEntity.getHeaders().get("Cookie");
//        log.info("cookie:{}", JSON.toJSONString(cookies));
//        return "";
//    }
//
//    @RequestMapping("/getCookie2")
//    public String getCookie2() {
//        String path = "http://127.0.0.1:8181/xxl-job-admin" + "/login";
//        Map<String, Object> hashMap = new HashMap();
//        hashMap.put("userName", "admin");
//        hashMap.put("password", "123456");
//        HttpResponse response = HttpRequest.post(path).form(hashMap).execute();
//        List<HttpCookie> cookies = response.getCookies();
//        StringBuilder sb = new StringBuilder();
//        for (HttpCookie cookie : cookies) {
//            sb.append(cookie.toString());
//        }
//        String cookie = sb.toString();
//        return cookie;
//    }
//
//    @RequestMapping("/addXxlJob")
//    public String addXxlJob(@RequestBody XxlJobInfo xxlJobInfo) {
//        log.info("传参：{}", JSON.toJSONString(xxlJobInfo));
//        String path = "http://127.0.0.1:8181/xxl-job-admin" + "/jobinfo/add";
//        String cookie = getCookie2();
//        log.info("cookie:{}", cookie);
//        HttpHeaders headers = new HttpHeaders();
//        headers.add(HttpHeaders.COOKIE, cookie);
//        log.info("请求头：{}", headers);
////        MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();      //请求体给予内容
//        Map<String, Object> map = BeanUtil.beanToMap(xxlJobInfo);
//        log.info("map:{}", JSON.toJSONString(map));
//        HttpEntity<MultiValueMap<String, String>> request = new HttpEntity(map, headers);
//        log.info("request:{}", JSON.toJSONString(request));
//        ResponseEntity<String> postForEntity = restTemplate.postForEntity(path, request, String.class);
//        return postForEntity.getBody();
//    }
//}
